package com.fr.chicken.service.Impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fr.chicken.dao.*;
import com.fr.chicken.facade.base.BaseResponseDTO;
import com.fr.chicken.facade.info.PlayerListInfo;
import com.fr.chicken.facade.request.*;
import com.fr.chicken.facade.response.*;
import com.fr.chicken.manager.account.AccountManager;
import com.fr.chicken.manager.account.EPlatformFlag;
import com.fr.chicken.manager.activation.ActivationManager;
import com.fr.chicken.manager.configure.ConfigManager;
import com.fr.chicken.manager.configure.EConfigure;
import com.fr.chicken.manager.house.HouseManager;
import com.fr.chicken.manager.logininfo.LoginInfoManager;
import com.fr.chicken.manager.playerinfo.PlayerInfoManager;
import com.fr.chicken.manager.share.ShareManager;
import com.fr.chicken.manager.verifcode.SMSVerifyCode;
import com.fr.chicken.model.*;
import com.fr.chicken.service.UserService;
import com.fr.chicken.util.JwtUtil;
import com.fr.chicken.util.Md5Util;
import com.fr.chicken.util.ValidateUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private AccountManager accountManager;
    @Autowired
    private PlayerInfoManager playerInfoManager;
    @Autowired
    private ActivationManager activationManager;
    @Autowired
    private LoginInfoManager loginInfoManager;
    @Autowired
    private HouseManager houseManager;
    @Autowired
    private PlayerInfoDao playerInfoDao;
    @Autowired
    private ChickenInfoDao chickenInfoDao;
    @Autowired
    private LoginInfoDao loginInfoDao;
    @Autowired
    private ActivationLogDao activationLogDao;
    @Autowired
    private AccountListDao accountListDao;
    @Autowired
    private GoodsLogDao goodsLogDao;

    @Autowired
    private ShareManager shareManager;

    @Autowired
    private ConfigManager configManager;


    private SMSVerifyCode smsVerifyCode = SMSVerifyCode.getInstance();

    @Override
    @Transactional
    public UserRegisterResponseDTO userRegister(UserRegisterRequsetDTO requsetDTO) {
        UserRegisterResponseDTO responseDTO = new UserRegisterResponseDTO();
        if(StringUtils.isBlank(requsetDTO.getNickName())){
            responseDTO.faild();
            responseDTO.setMsg("用户昵称不能为空");
            return responseDTO;
        }
        if(requsetDTO.getAccountInfo() == null || requsetDTO.getAccountInfo().isEmpty()){
            responseDTO.faild();
            responseDTO.setMsg("账号信息为空");
            return responseDTO;
        }
        if(!checkActivationCode(requsetDTO.getActivationCode(),responseDTO)){
            return responseDTO;
        }
        for(AccountInfo accountInfo : requsetDTO.getAccountInfo()){
            if (!checkCondition(accountInfo, responseDTO,requsetDTO.getPhoneCode(),requsetDTO)){
                // 验证失败
                return responseDTO;
            }
        }

        PlayerInfo playerInfo = playerInfoManager.createPlayer(requsetDTO.getNickName());

        activationManager.activationLogic(requsetDTO.getActivationCode(), playerInfo.getId());

        loginInfoManager.createLoginInfo(requsetDTO, playerInfo);

        // 注册账号
        for(AccountInfo accountInfo : requsetDTO.getAccountInfo()){
            accountManager.createAccountList(accountInfo, playerInfo.getId());
        }


        houseManager.createHouse(playerInfo.getId());

        String jwt = JwtUtil.generateToken("",playerInfo.getId().toString());
        responseDTO.setPlayerInfo(playerInfo);
        responseDTO.setAccessToken(jwt);
        responseDTO.success();
        responseDTO.setMsg("注册成功");
        return responseDTO;

    }

    /**
     * 验证注册条件
     * */
    private boolean checkCondition(AccountInfo accountInfo, UserRegisterResponseDTO responseDTO,String phoneCode,UserRegisterRequsetDTO requsetDTO) {
        if(accountInfo.getPlatformFlag() == EPlatformFlag.Phone.getVal()) {
            if (ValidateUtils.isMobile(accountInfo.getAccount()) == false) {
                responseDTO.faild();
                responseDTO.setMsg("手机号有误");
                return false;
            }
            boolean isphoneCode = smsVerifyCode.verify(accountInfo.getAccount(),phoneCode);
            if (!isphoneCode==true){
                responseDTO.faild();
                responseDTO.setMsg("验证码错误");
                return false;
            }
            if(!checkNickName(requsetDTO.getNickName(),responseDTO)){
                responseDTO.faild();
                responseDTO.setMsg("该昵称已存在");
                return false;
            }
        }
        if(accountInfo.getPlatformFlag() == EPlatformFlag.WeiChat.getVal()) {
            if(!checkNickName(requsetDTO.getNickName(),responseDTO)){
                requsetDTO.setNickName(requsetDTO.getNickName()+"_"+RandomStringUtils.randomAlphanumeric(3));
            }
        }
        if (!accountManager.checkAccountExistByPhoneNumber(accountInfo.getAccount())){
            responseDTO.faild();
            responseDTO.setMsg("账号已经被注册");
            return false;
        }

        return true;
    }

    private boolean checkNickName(String nickName, UserRegisterResponseDTO responseDTO) {
        if (playerInfoManager.checkNickNameExist(nickName)){
            responseDTO.faild();
            responseDTO.setMsg("该昵称已存在");
            return false;
        }
        return true;
    }

    private boolean checkActivationCode(String activationCode,UserRegisterResponseDTO responseDTO) {
        if (StringUtils.isBlank(activationCode)) {
            responseDTO.faild();
            responseDTO.setMsg("激活码为空");
            return false;
        }
        if(!playerInfoManager.checkActivationExist(activationCode)){
            responseDTO.faild();
            responseDTO.setMsg("激活码不存在");
            return false;
        }
        return true;
    }


    @Override
    public UserLoginResponseDTO userLogin(UserLoginRequsetDTO requsetDTO) {
        UserLoginResponseDTO responseDTO = new UserLoginResponseDTO();
        AccountList accountList = checkAccountAndPassword(responseDTO,requsetDTO.getPhoneNumber(),requsetDTO.getPhoneCode(),requsetDTO.getPlatformFlag());
        if(accountList == null){
            return responseDTO;
        }
        PlayerInfo playerInfo = playerInfoManager.findPlayerInfoById(accountList.getPlayerId().longValue());
        if (playerInfo.getStatus()==2){
            responseDTO.faild();
            responseDTO.setMsg("你已被封号");
            return responseDTO;
        }
        LoginInfo loginInfo = JSONObject.parseObject(JSON.toJSONString(requsetDTO),LoginInfo.class);
        loginInfo.setLoginTime(new Date());
        loginInfo.setPlayerId(playerInfo.getId());
        int num1 = loginInfoDao.insertSelective(loginInfo);
        if (num1<1){
            responseDTO.faild();
            responseDTO.setMsg("插入登录信息失败");
            return responseDTO;
        }
        responseDTO.setPlayerInfo(playerInfo);
        String jwt = JwtUtil.generateToken(requsetDTO.getPhoneNumber(),playerInfo.getId().toString());
        responseDTO.setAccessToken(jwt);
        responseDTO.success();
        responseDTO.setMsg("登录成功");
        return responseDTO;
    }

    private AccountList checkAccountAndPassword(UserLoginResponseDTO responseDTO,String account,String password,int platformFlag){
        AccountList accountList =  accountManager.findAccount(account);
        if ( accountList == null){
            responseDTO.faild();
            responseDTO.setMsg("账号不存在");
            return null;
        }
        if(accountList.getPlatformType() != platformFlag){
            responseDTO.faild();
            responseDTO.setMsg("平台不匹配");
            return null;
        }
        if(platformFlag == EPlatformFlag.Phone.getVal()){// 手机登录
            if (!accountList.getPassword().equals(Md5Util.getMD5(password).toLowerCase())){
                responseDTO.faild();
                responseDTO.setMsg("密码错误");
                return null;
            }
        }else if(platformFlag == EPlatformFlag.WeiChat.getVal()){// 微信登录
            if(accountList.getPassword() == null || !accountList.getPassword().equals(password)){
                responseDTO.faild();
                responseDTO.setMsg("密码错误");
                return null;
            }
        }else{
            responseDTO.faild();
            responseDTO.setMsg("未知平台");
        }
        return accountList;
    }

    @Override
    public UserGetPhoneCodeResponseDTO userGetPhoneCode(String phoneNumber) {
        UserGetPhoneCodeResponseDTO responseDTO = new UserGetPhoneCodeResponseDTO();
        if (!ValidateUtils.isMobile(phoneNumber)){
            responseDTO.faild();
            responseDTO.setMsg("手机号有误");
            return responseDTO;
        }
        String code = smsVerifyCode.createVerifyCode(phoneNumber);
//        responseDTO.setPhoneCode(code);
        if (code!=null){
            responseDTO.success();
            responseDTO.setMsg("发送验证码成功");
            return responseDTO;
        }
        responseDTO.faild();
        responseDTO.setMsg("发送验证码失败");
        return responseDTO;
    }

    @Override
    public GetPlayerInfoListResponseDTO getPlayerInfoList(GetPlayerInfoListRequsetDTO requsetDTO) {
        GetPlayerInfoListResponseDTO responseDTO = new GetPlayerInfoListResponseDTO();
        if (null != requsetDTO.getPageNum() && null != requsetDTO.getPageSize()) {
            PageHelper.startPage(requsetDTO.getPageNum(), requsetDTO.getPageSize());
        }
        List<PlayerInfo> playerInfos = playerInfoDao.selectByLikeId(requsetDTO.getPlayerId());
        PageInfo pageInfo = new PageInfo(playerInfos);
        List<PlayerListInfo> playerListInfos = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        for (PlayerInfo x:playerInfos){
            PlayerListInfo playerListInfo = JSONObject.parseObject(JSON.toJSONString(x),PlayerListInfo.class);
            HouseInfo houseInfo = houseManager.getHouseByPlayerId(x.getId());
            List<ChickenInfo> chickenInfos = chickenInfoDao.selectByHouseId(houseInfo.getId());
            playerListInfo.setChickenNums(chickenInfos.size());
            List<ActivationLog> activationLogs = activationLogDao.selectByInviterId(x.getId());
            playerListInfo.setSubordinateNums(activationLogs.size());
            playerListInfo.setLoginTime(sdf.format(loginInfoDao.selectByPrimaryKey(x.getCreateInfo()).getLoginTime()));
            playerListInfo.setRechargeNums(0);
            List<GoodsLog> goodsLogs = goodsLogDao.selectByPlayerId(x.getId());
            playerListInfo.setGoodsLogs(goodsLogs);
            List<AccountList> accountLists = accountManager.findAccountByPlayerId(x.getId());
            for (AccountList x1:accountLists){
                if (x1.getAccount().length()==11){
                      playerListInfo.setPhone(x1.getAccount());
                      break;
                }
            }
            playerListInfos.add(playerListInfo);
        }
        pageInfo.setList(playerListInfos);
        responseDTO.setPageInfo(pageInfo);
        responseDTO.success();
        responseDTO.setMsg("查询成功");
        return responseDTO;
    }

    @Override
    public GetPlayerInfoResponseDTO getPlayerInfo(Long playerId) {
        GetPlayerInfoResponseDTO responseDTO = new GetPlayerInfoResponseDTO();
        PlayerInfo playerInfo = playerInfoDao.selectByPrimaryKey(playerId);
        responseDTO.setPlayerInfo(playerInfo);
        responseDTO.success();
        responseDTO.setMsg("查询成功");
        return responseDTO;
    }

    @Override
    public BaseResponseDTO setStatus(Long playerId) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        PlayerInfo playerInfo = playerInfoDao.selectByPrimaryKey(playerId);
        if (playerInfo.getStatus()==1){
           playerInfo.setStatus((byte)2);
        }else {
            playerInfo.setStatus((byte)1);
        }
        int num = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num<1){
            responseDTO.faild();
            responseDTO.setMsg("失败");
            return responseDTO;
        }
        responseDTO.success();
        responseDTO.setMsg("成功");
        return responseDTO;
    }

    @Override
    public BaseResponseDTO setAgent(Long playerId) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        PlayerInfo playerInfo = playerInfoDao.selectByPrimaryKey(playerId);
        if (playerInfo.getAgent()!=1){
           playerInfo.setAgent(1);
        }else {
            playerInfo.setAgent(0);
        }
        int num = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num<1){
            responseDTO.faild();
            responseDTO.setMsg("失败");
            return responseDTO;
        }
        responseDTO.success();
        responseDTO.setMsg("成功");
        return responseDTO;
    }

    @Override
    public BaseResponseDTO setGeneralAgent(Long playerId) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        PlayerInfo playerInfo = playerInfoDao.selectByPrimaryKey(playerId);
        if (playerInfo.getAgent()!=2){
            playerInfo.setAgent(2);
        }else {
            playerInfo.setAgent(0);
        }
        int num = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num<1){
            responseDTO.faild();
            responseDTO.setMsg("失败");
            return responseDTO;
        }
        responseDTO.success();
        responseDTO.setMsg("成功");
        return responseDTO;
    }

    @Override
    public BaseResponseDTO setCharState(SetCharStateRequsetDTO requsetDTO) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        PlayerInfo playerInfo = playerInfoDao.selectByPrimaryKey(requsetDTO.getPlayerId());
        if (playerInfo.getCharState()==requsetDTO.getCharState()){
            responseDTO.faild();
            responseDTO.setMsg("无需变更");
            return responseDTO;
        }
        playerInfo.setCharState(requsetDTO.getCharState());
        int num = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num<1){
            responseDTO.faild();
            responseDTO.setMsg("失败");
            return responseDTO;
        }
        responseDTO.success();
        responseDTO.setMsg("成功");
        return responseDTO;
    }

    /**
     * 查询玩家绑定的所有平台
     * */
    @Override
    public QueryPlatformResponseDTO queryBindPlatform(long playerId) {
        QueryPlatformResponseDTO responseDTO = new QueryPlatformResponseDTO();
        responseDTO.setSuccess(true);
        responseDTO.setPlatforms(accountManager.queryPlayerPlatforms(playerId));
        return responseDTO;
    }

    @Override
    public BaseResponseDTO bindPlatform(BindPlatformRequest request) {
        BaseResponseDTO result = new BaseResponseDTO();
        if(request.getPlatform()==3){
            boolean isphoneCode = smsVerifyCode.verify(request.getAccount(),request.getPassword());
            if (!isphoneCode==true){
                result.faild();
                result.setMsg("验证码错误");
                return result;
            }
            request.setPassword(null);
        }
        if (!checkBindCondition(request, result)){ return result;}
        accountManager.createAccountList(request.getPlayerId(),request.getPlatform(),request.getAccount(),request.getPassword());
        result.success();
        return result;
    }

    @Override
    public BaseResponseDTO updateUserInfo(UpdateUserInfoRequsetDTO requsetDTO) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        PlayerInfo playerInfo2 = playerInfoDao.selectByPrimaryKey(requsetDTO.getPlayerId());
        if (!StringUtils.isBlank(requsetDTO.getNickName())){
            PlayerInfo playerInfo1 = playerInfoDao.selectByNickName(requsetDTO.getNickName());
            if(playerInfo1 != null) {
                if (!playerInfo1.getId().equals(requsetDTO.getPlayerId())) {
                    requsetDTO.setNickName(requsetDTO.getNickName() + "_" + RandomStringUtils.randomAlphanumeric(3));
                }
                else {
                    requsetDTO.setNickName(playerInfo2.getNickName());
                }
            }
        }else {
            responseDTO.faild();
            responseDTO.setMsg("昵称不能为空");
            return responseDTO;
        }
        PlayerInfo playerInfo = JSONObject.parseObject(JSON.toJSONString(requsetDTO),PlayerInfo.class);
        playerInfo.setId(requsetDTO.getPlayerId());
        int num  = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num<1){
            responseDTO.faild();
            responseDTO.setMsg("失败");
            return responseDTO;
        }
        responseDTO.success();
        responseDTO.setMsg("成功");
        return responseDTO;
    }

    @Override
    public BaseResponseDTO userMessageConsume(QueryPlatformRequestDTO requestDTO) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        PlayerInfo playerInfo = playerInfoDao.selectByPrimaryKey(requestDTO.getPlayerId());
        int maxConfigure = configManager.getIntConfig(10);
        if (playerInfo.getEgg()<maxConfigure){
            responseDTO.faild();
            responseDTO.setMsg("鸡蛋数量不足");
            return responseDTO;
        }
        playerInfo.setEgg(playerInfo.getEgg()-maxConfigure);
        int num = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num<1){
            responseDTO.faild();
            responseDTO.setMsg("失败");
            return responseDTO;
        }
        responseDTO.success();
        responseDTO.setMsg("成功");
        return responseDTO;
    }

    @Override
    public GetPlayerLoginListResponseDTO getPlayerLoginList(GetPlayerLoginListRequsetDTO requsetDTO) {
        GetPlayerLoginListResponseDTO responseDTO = new GetPlayerLoginListResponseDTO();
        if (null != requsetDTO.getPageNum() && null != requsetDTO.getPageSize()) {
            PageHelper.startPage(requsetDTO.getPageNum(), requsetDTO.getPageSize());
        }
        List<LoginInfo> loginInfos = loginInfoDao.selectByPlayerId(requsetDTO.getPlayerId());
        PageInfo pageInfo = new PageInfo(loginInfos);
        pageInfo.setList(loginInfos);
        responseDTO.setPageInfo(pageInfo);
        responseDTO.success();
        responseDTO.setMsg("查询成功");
        return responseDTO;
    }

    @Override
    @Transactional
    public BaseResponseDTO insertUser(InsertUserRequsetDTO requsetDTO) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        if (StringUtils.isBlank(requsetDTO.getNickName()) || StringUtils.isBlank(requsetDTO.getPhoneNumber()) || StringUtils.isBlank(requsetDTO.getPassword())){
               responseDTO.faild();
               responseDTO.setMsg("请填写完整信息");
               return responseDTO;
        }
        if (!accountManager.checkAccountExistByPhoneNumber(requsetDTO.getPhoneNumber())){
            responseDTO.faild();
            responseDTO.setMsg("手机号已经被注册");
            return responseDTO;
        }
        if (playerInfoManager.checkNickNameExist(requsetDTO.getNickName())){
            responseDTO.faild();
            responseDTO.setMsg("该昵称已存在");
            return responseDTO;
        }
        PlayerInfo playerInfo = new PlayerInfo();
        playerInfo.setNickName(requsetDTO.getNickName());
        int num = playerInfoDao.insertSelective(playerInfo);
        if(num<1){
            throw new RuntimeException("插入玩家信息失败");
        }
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setLoginTime(new Date());
        loginInfo.setPlayerId(playerInfo.getId());
        loginInfo.setPlatformFlag(3);
        loginInfo.setLoginIp(requsetDTO.getLoginIp());
        int num1 = loginInfoDao.insertSelective(loginInfo);
        if (num1<1){
            throw new RuntimeException("插入注册信息失败");
        }
        playerInfo.setCreateInfo(loginInfo.getId());
        int num2 = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num2<1){
            throw new RuntimeException("更新用户信息失败");
        }
        AccountList accountList = new AccountList();
        accountList.setPlayerId(playerInfo.getId());
        accountList.setPlatformType(3);
        accountList.setAccount(requsetDTO.getPhoneNumber());
        accountList.setPassword(Md5Util.getMD5(requsetDTO.getPassword()).toLowerCase());
        int num3 = accountListDao.insertSelective(accountList);
        if (num3<1){
            throw new RuntimeException("插入用户信息失败");
        }
        houseManager.createHouse(playerInfo.getId());
        responseDTO.success();
        responseDTO.setMsg("添加成功");
        return responseDTO;
    }

    @Override
    @Transactional
    public BaseResponseDTO insertGoodsLog(QueryPlatformRequestDTO requestDTO) {
        BaseResponseDTO responseDTO = new BaseResponseDTO();
        PlayerInfo playerInfo = playerInfoDao.selectByPrimaryKey(requestDTO.getPlayerId());
        if(playerInfo==null){
            responseDTO.faild();
            responseDTO.setMsg("用户不存在");
            return responseDTO;
        }
        GoodsLog goodsLog = new GoodsLog();
        goodsLog.setGoodsId(1);
        goodsLog.setInfo(activationManager.generateActivation());
        goodsLog.setTime(System.currentTimeMillis()/1000);
        goodsLog.setPlayerId(requestDTO.getPlayerId());
        int num = goodsLogDao.insertSelective(goodsLog);
        if (num<1){
            throw new RuntimeException("添加失败");
        }
        playerInfo.setActivationCodeNums(playerInfo.getActivationCodeNums()+1);
        int num1 = playerInfoDao.updateByPrimaryKeySelective(playerInfo);
        if (num1<1){
            throw new RuntimeException("添加失败");
        }
        responseDTO.success();
        responseDTO.setMsg("添加成功");
        return responseDTO;
    }

    @Override
    public GetUserActivationListResponseDTO getUserActivationList(Long playerId) {
        GetUserActivationListResponseDTO responseDTO = new GetUserActivationListResponseDTO();
        List<GoodsLog> goodsLogs = goodsLogDao.selectByPlayerId(playerId);
        responseDTO.setGoodsLogs(goodsLogs);
        responseDTO.success();
        responseDTO.setMsg("查询成功");
        return responseDTO;
    }

    /**
     * 分享
     * */
    @Override
    public BaseResponseDTO share(long playerId) {
        BaseResponseDTO response = new BaseResponseDTO();
        PlayerInfo playerInfo = playerInfoManager.findPlayerInfoById(playerId);
        if(playerInfo == null){
            response.setSuccess(false);
            return response;
        }

        synchronized (playerInfo){
            if(shareManager.isTodayFistShare(playerId)){// 如果是今日第一次分享
                if(shareManager.isFirstShare(playerId)){// 如果是第一次分享
                    // 增加第一次分享的奖励
                    playerInfo.setEgg(playerInfo.getEgg() + configManager.getIntConfig(EConfigure.FirstShareAward));
                }else{
                    // 增加每日分享的奖励
                    playerInfo.setFeaces(playerInfo.getFeaces() + configManager.getIntConfig(EConfigure.DayShareAward));
                }
            }
            playerInfoDao.updateByPrimaryKey(playerInfo);
        }
        // 添加分享记录
        shareManager.share(playerId);
        response.setSuccess(true);
        return response;
    }

    public boolean checkBindCondition(BindPlatformRequest request, BaseResponseDTO result) {
        List<Integer> bindPPlatforms = accountManager.queryPlayerPlatforms(request.getPlayerId());
        if(bindPPlatforms == null || bindPPlatforms.isEmpty() ){
            result.setSuccess(false);
            result.setMsg("ID无效");
            return false;
        }
        if(!EPlatformFlag.valid(request.getPlatform())){
            result.setSuccess(false);
            result.setMsg("平台无效");
            return false;
        }
        if(accountManager.checkPlayerBindedPlatforms(request.getPlayerId(),request.getPlatform())){
            result.setSuccess(false);
            result.setMsg("已经绑定过该平台");
            return false;
        }
        if(StringUtils.isBlank(request.getAccount())){
            result.setSuccess(false);
            result.setMsg("账号无效");
            return false;
        }
        if(!accountManager.checkAccountExistByPhoneNumber(request.getAccount())){
            result.setSuccess(false);
            if (request.getPlatform()==2){
                result.setMsg("该微信已经被绑定过了");
            }if (request.getPlatform()==3) {
                result.setMsg("该手机已经被绑定过了");
            }
            return false;
        }

        if(request.getPlatform() != EPlatformFlag.Phone.getVal() && request.getPassword() == null){
            result.setSuccess(false);
            result.setMsg("密码无效");
            return false;
        }
        return true;
    }
}

